///////////////////////////////////////////////////////////
///////////////// Have an itch? Scratch it! ///////////////
///////////////////////// SCRATCH /////////////////////////
/////////////////////  A MUD  Server   ////////////////////
///////////////////// By: Jared Devall ////////////////////
/////////////////////      Thanks:     ////////////////////
/////////////////////  DIKU/Merc/ROM   ////////////////////
///////////////////// Aetas/Deus Gang  ////////////////////
/////////////////////       Beej       ////////////////////
///////////////////////////////////////////////////////////
// Altered by CTonk ( ctonk87@hotmail.com )

// main.cpp

#include "src/setup.cpp"

int main( int argc, char *argv[] )
{
	int port = portNumber; // The port of the Server, with a default value.
	bool copyover = false;
	std::string buf;


	if ( argc >= 2 )
	{
		if ( str_cmp( argv[1], "-copyover-" ) )
		{
			copyover = true;
			SocketServer::Instance().SetHostSocket( atoi(argv[2]) );
		}
		else
		{
			if ( atoi( argv[1] ) <= 1024 )
			{ // Ports from 1024 and below are Reserved.
				std::cout << "Port #" << argv[1] << " Reserved. ( # < 1024 )" << endl; 
				exit( 1 );
			}
			else if ( atoi( argv[1] ) > 65535 )
			{ // No ports above 65535.
				std::cout << "Port #" << argv[1] << " Out of Range. ( # > 65535 )" << endl;
				exit( 1 );
			}
			else
			{ // The Port the user gave is okay.
				port = atoi( argv[1] );
			}
		}
	}

    // Start the game...

	SocketServer::Instance().Start();

	std::cout << "\n\t" << "Symphony is running on port " << port << endl;
	buf << "Server launched on port " << port << '.';
	log( server, buf );

	// World::Instance()._exists can be set to false by shutdown or copyover.
	while( World::Instance()._exists )
		World::Instance().Monitor();

	std::cout << "Shutdown successful: ";

	return 0;
}
